package com.yfbao.horizon.docker.config;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Slf4j
@Configuration
public class MyConfiguration {

    @Autowired
    private JdbcProp jdbcProp;

    @Bean("dataSource")
    public DataSource druidDatasource(){
        DruidDataSource dataSource = new DruidDataSource();
        log.info("url:"+jdbcProp.getUrl());
        dataSource.setDriverClassName(this.jdbcProp.getDriverClassName());  //这里的this代表全局变量 不可以在函数括号中写 此处也可以省略this
        dataSource.setUrl(this.jdbcProp.getUrl());
        dataSource.setUsername(this.jdbcProp.getUsername());
        dataSource.setPassword(this.jdbcProp.getPassword());
        return dataSource;
    }
}
